﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace Arch.DomainServices.Metadata
{
    public class EntityBuilder : MetadataBuilder
    {
        public IDictionary<string, IList<Attribute>> Attributes { get; set; }
        public Type Type { get; set; }

        public EntityBuilder(Type entityType, DomainMetadataProvider metadataProvider)
            : base(metadataProvider)
        {
            Attributes = new Dictionary<string, IList<Attribute>>();
            Type = entityType;
        }
    }

    public class EntityBuilder<T> : EntityBuilder
    {
        public EntityBuilder(DomainMetadataProvider metadataProvider)
            : base(typeof(T), metadataProvider)
        {
            metadataProvider.Register(this);
        }

        public EntityBuilder<T> ForProperty<TProperty>(Expression<Func<T, TProperty>> expression, params Attribute[] attributes)
        {
            string member = ((MemberExpression)expression.Body).Member.Name;
            if (!Attributes.ContainsKey(member))
            {
                var list = new List<Attribute>(attributes);
                Attributes.Add(member, list);
            }

            return this;
        }
    }
}
